import dayjs from 'dayjs'
import { sourceMap, recheckStatusMap, autoClassStatusMap } from '@/utils/dict'
// 定义分类渲染
export function renderClassification({ row }, showType = true) {
  return (
    <>
      <span>
        {row.handClassificationName
          ? `${row.handClassificationName}`
          : row.classificationName
            ? `${row.classificationName}`
            : '--'}
      </span>
    </>
  )
}

// 定义分级渲染
export function renderLevel({ row }, showType = true) {
  let level
  if (row.handLevelName) {
    level = `${row.handLevelName}`
  } else if (row.levelName) {
    level = `${row.levelName}`
  } else {
    level = '--'
  }
  return (
    <>
      <span>{level}</span>
    </>
  )
}

// 定义文件指纹
export function renderFinger({ row }) {
  const md5String = row.md5?.toString()
  const kfsString = row.kfs?.toString()
  const pfsString = row.pfs?.toString()
  const psaString = row.psa?.toString()
  return (
    <>
      <div>
        <el-tooltip
          placement="top"
          v-slots={{
            content: () => <div style="max-width: 90vw;">{md5String || '无'}</div>
          }}
        >
          <span>MD5,</span>
        </el-tooltip>
        <el-tooltip
          placement="top"
          v-slots={{
            content: () => <div style="max-width: 90vw;">{kfsString || '无'}</div>
          }}
        >
          <span>KFS,</span>
        </el-tooltip>
        <el-tooltip
          placement="top"
          v-slots={{
            content: () => <div style="max-width: 90vw;">{pfsString || '无'}</div>
          }}
        >
          <span>PFS,</span>
        </el-tooltip>
        <el-tooltip
          placement="top"
          v-slots={{
            content: () => <div style="max-width: 90vw;">{psaString || '无'}</div>
          }}
        >
          <span>PSA</span>
        </el-tooltip>
      </div>
    </>
  )
}

// 定义抽样数据渲染
export function renderSamples({ row }) {
  const sampleString = row.samples.join(',')
  const sampleHtml = row.samples.join('\n')
  const content = `<span style="white-space: pre-line">${sampleHtml}</span>`
  return (
    <>
      <el-tooltip content={content} raw-content>
        <div class="w-160px overflow-hidden text-ellipsis whitespace-nowrap">{sampleString}</div>
      </el-tooltip>
    </>
  )
}
// 定义分类变更
export function classificationChangeRender({ row }) {
  let renderChange
  if (row.newClassificationName && row.newClassificationName !== row.oldClassificationName) {
    renderChange = `${row.oldClassificationName}->${row.newClassificationName}`
  } else {
    renderChange = '无变更'
  }
  return (
    <>
      <span>{renderChange}</span>
    </>
  )
}
// 定义分级变更
export function levelChangeRender({ row }) {
  let renderChange
  if (row.newLevelName && row.newLevelName !== row.oldLevelName) {
    renderChange = `${row.oldLevelName}->${row.newLevelName}`
  } else {
    renderChange = '无变更'
  }
  return (
    <>
      <span>{renderChange}</span>
    </>
  )
}
// 定义重要程度变更
export function importanceChangeRender({ row }) {
  return (
    <>
      <span>
        {row.oldImportance}
        {'->'}
        {row.importance}
      </span>
    </>
  )
}
// 文件来源
export function sourceRender({ row }) {
  return (
    <>
      <span>{sourceMap.has(row.source) ? sourceMap.get(row.source) : '--'}</span>
    </>
  )
}
// 复核状态
export function recheckStatusRender({ row }) {
  return (
    <>
      <span>
        {recheckStatusMap.has(row.recheckStatus) ? recheckStatusMap.get(row.recheckStatus) : '--'}
      </span>
    </>
  )
}
// 自动分类分级状态
export function autoClassStatusRender({ row }) {
  return (
    <>
      <span>
        {autoClassStatusMap.has(row.autoClassStatus)
          ? autoClassStatusMap.get(row.autoClassStatus)
          : '--'}
      </span>
    </>
  )
}
